package decrypt;

public class Solution {
    public int[] decrypt(int[] code, int k) {
        int n = code.length;
        int[] ans = new int[n];
        if(k == 0){
            return ans;
        }
        if(k>0){
            for (int i = 0; i < code.length; i++) {
                int sum = 0;
                for (int j = 1; j <= k; j++) {
                    sum+=(code[(j+i)%n]);
                }
                ans[i] = sum;
            }
            return ans;
        }
        if(k<0){
            for (int i = 0; i < code.length; i++) {
                int sum = 0;
                for (int j = k; j >=1 ; j--) {
                    sum+=(code[(n+(i-j))%n]);
                }
                ans[i] = sum;
            }
            return ans;
        }
        return null;
    }
}
